package com.wsc.wisdomchina.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.wsc.wisdomchina.R;
import com.wsc.wisdomchina.Tools.Tools;
import com.wsc.wisdomchina.javaBean.FeedBackListBean;

import java.util.Date;
import java.util.List;

/**
 * 百姓监督列表适配器
 * Created by ${wangtao} on 2017/3/9.
 */

public class PeopleControlAdapter extends BaseAdapter {
    private Context context;
    private List<FeedBackListBean> messageBeen;
    private boolean isShowAuth;

    public PeopleControlAdapter(Context context, List<FeedBackListBean> messageBeen,boolean isShowAuth) {
        this.context = context;
        this.messageBeen = messageBeen;
        this.isShowAuth=isShowAuth;
    }

    @Override
    public int getCount() {
        return messageBeen.size();
    }

    @Override
    public Object getItem(int position) {
        return messageBeen.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder holder = null;
        View view = convertView;
        if (view == null) {
            view = LayoutInflater.from(context).inflate(R.layout.peoplecontrol_item, null);
            holder = new ViewHolder(view);
            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }

        FeedBackListBean feedBackListBean=(FeedBackListBean) getItem(position);

        holder.item_bxjdl_title.setText(feedBackListBean.getTitle());
        holder.item_bxjdl_content.setText(feedBackListBean.getContent());
        if(isShowAuth)
            holder.item_bxjdl_name.setText(feedBackListBean.getAuthor());
        else
            holder.item_bxjdl_name.setText(feedBackListBean.getStreetName());
        holder.item_bxjdl_guanzhu.setText(String.valueOf(feedBackListBean.getSeeCount()));

       if (feedBackListBean.getState() == 1) {
            holder.item_bxjdl_solve.setText("处理中");
            holder.item_bxjdl_solve.setTextColor(Color.parseColor("#15CD1F"));
        } else if (feedBackListBean.getState() == 2) {
            holder.item_bxjdl_solve.setText("已解决");
            holder.item_bxjdl_solve.setTextColor(Color.parseColor("#1ED4E9"));
        }else {
            holder.item_bxjdl_solve.setText("未解决");
            holder.item_bxjdl_solve.setTextColor(Color.parseColor("#E9411E"));
        }

        String date_time = Tools.formatDateTimeyyyyMMDDhhmm(new Date(feedBackListBean.getCrt()));
        holder.item_bxjdl_time.setText(date_time);

        if (feedBackListBean.getBanners().size() == 0) {
            holder.item_bxjdl2.setVisibility(View.GONE);
        } else if (feedBackListBean.getBanners().size() == 1) {
            holder.item_bxjdl2.setVisibility(View.VISIBLE);
            holder.item_bxjdl_image_one.setVisibility(View.VISIBLE);
            holder.item_bxjdl_image_two.setVisibility(View.INVISIBLE);
            holder.item_bxjdl_image_three.setVisibility(View.INVISIBLE);
            Glide.with(context).load(feedBackListBean.getBanners().get(0)).into(holder.item_bxjdl_image_one);
        } else if (feedBackListBean.getBanners().size() == 2) {
            holder.item_bxjdl2.setVisibility(View.VISIBLE);
            holder.item_bxjdl_image_one.setVisibility(View.VISIBLE);
            holder.item_bxjdl_image_two.setVisibility(View.VISIBLE);
            holder.item_bxjdl_image_three.setVisibility(View.INVISIBLE);
            Glide.with(context).load(feedBackListBean.getBanners().get(0)).into(holder.item_bxjdl_image_one);
            Glide.with(context).load(feedBackListBean.getBanners().get(1)).into(holder.item_bxjdl_image_two);
        } else if (feedBackListBean.getBanners().size() >= 3) {
            holder.item_bxjdl2.setVisibility(View.VISIBLE);
            holder.item_bxjdl_image_one.setVisibility(View.VISIBLE);
            holder.item_bxjdl_image_two.setVisibility(View.VISIBLE);
            holder.item_bxjdl_image_three.setVisibility(View.VISIBLE);
            Glide.with(context).load(feedBackListBean.getBanners().get(0)).into(holder.item_bxjdl_image_one);
            Glide.with(context).load(feedBackListBean.getBanners().get(1)).into(holder.item_bxjdl_image_two);
            Glide.with(context).load(feedBackListBean.getBanners().get(2)).into(holder.item_bxjdl_image_three);
        }

        return view;
    }

    protected class ViewHolder {
        private TextView item_bxjdl_title;
        private TextView item_bxjdl_solve;
        private TextView item_bxjdl_content;
        private TextView item_bxjdl_name;
        private TextView item_bxjdl_time;
        private TextView item_bxjdl_guanzhu;
        private LinearLayout item_bxjdl2;
        private ImageView item_bxjdl_image_one;
        private ImageView item_bxjdl_image_two;
        private ImageView item_bxjdl_image_three;

        public ViewHolder(View view) {
            item_bxjdl_title = (TextView) view.findViewById(R.id.item_bxjdl_title);
            item_bxjdl_solve = (TextView) view.findViewById(R.id.item_bxjdl_solve);
            item_bxjdl_content = (TextView) view.findViewById(R.id.item_bxjdl_content);
            item_bxjdl_name = (TextView) view.findViewById(R.id.item_bxjdl_name);
            item_bxjdl_time = (TextView) view.findViewById(R.id.item_bxjdl_time);
            item_bxjdl_guanzhu = (TextView) view.findViewById(R.id.item_bxjdl_guanzhu);

            item_bxjdl2 = (LinearLayout) view.findViewById(R.id.item_bxjdl2);
            item_bxjdl_image_one = (ImageView) view.findViewById(R.id.item_bxjdl_image_one);
            item_bxjdl_image_two = (ImageView) view.findViewById(R.id.item_bxjdl_image_two);
            item_bxjdl_image_three = (ImageView) view.findViewById(R.id.item_bxjdl_image_three);
        }
    }

}
